package com.taiyi.renaissancemall.ui.main.first.goodSelect;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.taiyi.renaissancemall.R;
import com.taiyi.renaissancemall.Utils.RoundedCornersTransformation;
import com.taiyi.renaissancemall.bean.HotBrandBean;
import com.taiyi.renaissancemall.bean.MyScoresBean;
import com.taiyi.renaissancemall.ui.main.brand.BrandListActivity;
import com.taiyi.renaissancemall.ui.main.goodsdetail.GoodsDetailActivity;

import java.util.List;

import rx.internal.schedulers.NewThreadWorker;

public class GoodSelectAdapter extends BaseQuickAdapter<HotBrandBean.CartListBean, BaseViewHolder> {
    public GoodSelectAdapter(int layoutResId, @Nullable List<HotBrandBean.CartListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HotBrandBean.CartListBean item) {
        ImageView img = helper.getView(R.id.iv_good_select_icon);

        // 圆角图片 new RoundedCornersTransformation 参数为 ：半径 , 外边距 , 圆角方向(ALL,BOTTOM,TOP,RIGHT,LEFT,BOTTOM_LEFT等等)
        //顶部左边圆角
        RoundedCornersTransformation transformation = new RoundedCornersTransformation
                (15, 0, RoundedCornersTransformation.CornerType.TOP_LEFT);
        //顶部右边圆角
        RoundedCornersTransformation transformation1 = new RoundedCornersTransformation
                (15, 0, RoundedCornersTransformation.CornerType.TOP_RIGHT);
//        //下部左边圆角
//        RoundedCornersTransformation transformation2 = new RoundedCornersTransformation
//                (15, 0, RoundedCornersTransformation.CornerType.BOTTOM_LEFT);
//        //下部右边圆角
//        RoundedCornersTransformation transformation3 = new RoundedCornersTransformation
//                (15, 0, RoundedCornersTransformation.CornerType.BOTTOM_RIGHT);

        //组合各种Transformation,
        MultiTransformation<Bitmap> mation = new MultiTransformation<>
                //Glide设置圆角图片后设置ImageVIew的scanType="centerCrop"无效解决办法,将new CenterCrop()添加至此
                (new CenterCrop(), transformation, transformation1);

        Glide.with(mContext)
                .load(item.introimg)
                //切圆形
                .apply(RequestOptions.bitmapTransform(mation))
                .into(img);

//        RoundedCorners roundedCorners = new RoundedCorners(15);
//        RequestOptions transform = new RequestOptions().transform(roundedCorners);
//        Glide.with(mContext).load(item.introimg).apply(transform).into(img);
        RecyclerView recyclerView = helper.getView(R.id.rlv_good_select_list);

        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, BrandListActivity.class);
                intent.putExtra("brandId", String.valueOf(item.brandid));
                intent.putExtra("brandName", item.brandname);
                mContext.startActivity(intent);
            }
        });

        GoodSelectItemAdapter goodSelectAdapter = new GoodSelectItemAdapter(R.layout.layout_good_selects_item, item.details);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        recyclerView.setAdapter(goodSelectAdapter);
        goodSelectAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(mContext, GoodsDetailActivity.class);
                intent.putExtra("commodityId", item.details.get(position).commodityid);
                mContext.startActivity(intent);
            }
        });
    }
}
